<template>
	<view class="exam-content">
		<!-- 第一步 考试须知 -->
		<Notice :buyInfo="buyInfo" :currentTag="currentTag" :examAddress="examAddress" @getSteps="getSteps"
			v-if="steps == 1"></Notice>
		<!-- 考试中... -->
		<Examination @getSteps="getSteps" :currentTag="currentTag" :examAddress="examAddress" v-if="steps == 2"></Examination>
		<!-- 考试结果 -->
		<ExamResult @getSteps="getSteps" :currentTag="currentTag" :examTotal="examTotal" v-if="steps == 3"></ExamResult>
		<!-- 考试结果详情 -->
		<exam-details @getSteps="getSteps" :currentTag="currentTag" :examTotalId="examTotalId" v-if="steps == 4"></exam-details> 
	</view>
</template>

<script>
	import Notice from "./components/instructions";
	import Examination from "./components/examination";
	import ExamResult from "./components/examResult";
	import ExamDetails from "./components/examDetails.vue";

	export default {
		data() {
			return {
				steps: 1,
				buyInfo: {
					isBuy: false,
					tryNum: 5
				},
				currentTag: 1,
				userInfo: {},
				// 随机考台
				examAddress: Math.floor(Math.random() * (100 - 1) + 1),
				// 考试结果
				examTotal: 0,
				examTotalId:0,
				
				// 
				subject:1,
			}
		},
		components: {
			Notice,
			Examination,
			ExamResult,
			ExamDetails
		},
		watch: {
			steps(newValue, oldValue) {
				if (newValue == 2) {
					uni.setNavigationBarTitle({
						title: '考试'
					});
				}
				if (newValue == 3) {
					uni.setNavigationBarTitle({
						title: '考试结果'
					});
				}
			}
		},
		onLoad(options) {
			// console.log(options.currentTag,88888)
			if(options.currentTag==4){
				this.subject=2
			}
			if(options.currentTag != undefined) {
				this.currentTag = options.currentTag;
			}
			if(options.result != undefined) {
				let obj = JSON.parse(options.result);
				this.steps=4;
				this.examTotalId = obj.id;
			}
		},
		// onBackPress(e) {
		// 	console.log(888888888,e);
		// },
		onUnload() {
			// uni.showModal({
			// 	title: '提示',
			// 	content: '这是一个模态弹窗',
			// 	success: function (res) {
			// 		if (res.confirm) {
			// 			console.log('用户点击确定');
			// 		} else if (res.cancel) {
			// 			console.log('用户点击取消');
			// 		}
			// 	}
			// });
		},
		mounted() {
			
		},
		methods: {
			// 获取组件种传回来的步骤数
			getSteps(steps, res) {
				// console.log(2222222,steps)
				// console.log(steps,'步数');
				// console.log(res,'步数');
				this.$nextTick(() => {
					this.steps = steps;
					if (res != undefined) {
						this.examTotal = res.scores;
						this.examTotalId = res.id;
					}
				})
			},
		}
	}
</script>

<style lang="scss">

</style>